<template>
  <div class="page-container">
    <!--工具栏-->
    <div class="toolbar" style="float:left;padding-top:10px;padding-left:15px;">
      <el-form :inline="true" :model="filters" :size="size">
        <el-form-item>
          <el-input v-model="filters.orderNo" clearable placeholder="充值卡编号"/>
        </el-form-item>
        <el-form-item>
          <el-input v-model="filters.username" clearable placeholder="用户名称"/>
        </el-form-item>
        <el-form-item>
          <el-input v-model="filters.remains" clearable placeholder="充值卡余额"/>
        </el-form-item>
        <!-- 按钮 -->
        <el-form-item>
          <kt-button
            icon="fa fa-search"
            :label="$t('action.search')"
            type="primary"
            @click="findPage(null)"/>
        </el-form-item>

        <el-form-item>
          <kt-button icon="fa fa-refresh" :label="$t('action.reset')" type="primary" @click="resetForm('filters')" />
        </el-form-item>
      </el-form>
    </div>
    <!--表格内容栏-->
    <cy-table
      :height="350"
      :highlightCurrentRow="true"
      :data="pageResult"
      :columns="filterColumns"
      :showSelection="false"
      :showDeleteOperation="false"
      :showBatchDelete="false"
      :showOperation="false"
      :showEditOperation="false"
      @findPage="findPage"
      @handleDelete="handleDelete"
      ref="CyTable">
    </cy-table>

  </div>
</template>

<script>
  import CyTable from "@/views/Core/CyTable";
  import KtButton from "@/views/Core/KtButton";
  import { format, formatDate } from "@/utils/datetime";
  import TableColumnFilterDialog from "@/views/Core/TableColumnFilterDialog";
  export default {
    components: {
      KtButton,
      CyTable,
      TableColumnFilterDialog
    },
    data() {
      return {
        size: "small",
        filters: {
          orderNo: "",
          username: "",
          remains: "",
          t: "orderSubCard"
        },
        optionShop: [],
        columns: [
          {prop: "orderNo", label: "订单编号", minWidth: 120},
          {prop: "pay_money", label: "付款金额", minWidth: 120},
          {prop: "create_time", label: "创建时间", minWidth: 120},
          {prop: "cardNo", label: "充值卡编号", minWidth: 120},
          {prop: "remains", label: "余额", minWidth: 120},
          {prop: "username", label: "用户名称", minWidth: 120}
        ],
        pageRequest: {pageNum: 1, pageSize: 10},
        pageResult: {},
        filterColumns: [],
      };
    },
    mounted() {
      this.initColumns();
    },
    methods: {
      // 获取分页数据
      findPage: function (data) {
        this.filters.t = "orderSubCard";
        this.$refs.CyTable.findPage(this.filters);
      },
      // 批量删除
      handleDelete: function (data) {
        var ids = '';
        for (var i = 0; i < data.params.length; i++) {
          ids = ids + data.params[i].id + ',';
        }
        data.t = 'orderSubCard'
        data.ids = ids
        this.utils.request.deleteUserInfo(data, data.callback)
      },
      // 显示编辑界面
      handleEdit: function(params) {
        this.editDialogVisible = true;
        this.operation = false;
        this.$nextTick(function() {
          this.dataForm = Object.assign({}, params.row);
        });
      },
      // 编辑
      submitForm: function() {
        this.$refs.dataForm.validate(valid => {
          if (valid) {
            this.$confirm("确认提交吗？", "提示", {}).then(() => {
              let params = Object.assign({}, this.dataForm);
              params.t = "orderSubCard";
              var this_ = this;
              this.utils.request.editInfo(params, function(res) {
                if (res.code == "0000") {
                  this_.$message({ message: "操作成功", type: "success" });

                  this_.$refs["dataForm"].resetFields();

                  this_.editDialogVisible = false;

                  this_.findPage(null);
                } else {
                  this_.$message({
                    message: "操作失败, " + res.msg,
                    type: "error"
                  });
                }
              });
            });
          }
        });
      },
      // 时间格式化
      dateFormat: function(row, column, cellValue, index) {
        return format(row[column.property]);
      },
      // 重置
      resetForm(formName) {
        this.filters = {
          nums: "",
          nickname: ""
        };
        this.findPage();
      },
      // 处理表格列过滤显示
      displayFilterColumnsDialog: function () {
        this.$refs.tableColumnFilterDialog.setDialogVisible(true)
      },
      handleFilterColumns: function (data) {
        this.filterColumns = data.filterColumns
        this.$refs.tableColumnFilterDialog.setDialogVisible(false)
      },
      initColumns: function () {
        var temp = [];
        $.each(this.columns, function (key, val) {
          temp.push(val)
        })
        this.filterColumns = temp;
      },
    }
  };
</script>

<style scoped>

</style>
